package service

import (
	"github.com/gin-gonic/gin"
	"zk2/product-guard/internal/dto"
	"zk2/product-guard/internal/model"
	"zk2/product-guard/response"
)

func CreateWindow(c *gin.Context) {

	var window model.Window
	err := c.ShouldBind(&window)
	if err != nil {
		response.Error(c, "参数错误")
		return
	}
	dto.FindWindow(&window, window.ShopId)
	if window.ID != 0 {
		response.Error(c, "该商品已关联橱窗")
		return
	}
	window = model.Window{
		Name:     window.Name,
		Username: window.Username,
		Class:    window.Class,
		ShopId:   window.ShopId,
	}
	err = dto.CreateWindow(&window)
	if err != nil {
		response.Error(c, "添加失败")
		return
	}
	response.Success(c, "添加成功", window.ID)
}
